<?php 
/*
 * This filter convert simple array to tree array
 * and sort it
 *  
 */
class Zen_Filter_Alias implements Zend_Filter_Interface
{
    private $letters = array(
			"а" => "a", "б" => "b", "в" => "v", "г" => "g", "д" => "d", "е" => "e",
			"ё" => "e", "ж" => "zh", "з" => "z", "и" => "i", "й" => "j", "к" => "k",
            "л" => "l", "м" => "m", "н" => "n", "о" => "o", "п" => "p", "р" => "r",
            "с" => "s", "т" => "t", "у" => "u", "ф" => "f", "х" => "h", "ц" => "c",
            "ч" => "ch", "ш" => "sh", "щ" => "sh", "ы" => "i", "ь" => "", "ъ" => "",
            "э" => "e", "ю" => "yu", "я" => "ya",
			"А" => "A", "Б" => "B", "В" => "V", "Г" => "G", "Д" => "D", "Е" => "E",
			"Ё" => "E", "Ж" => "ZH", "З" => "Z", "И" => "I", "Й" => "J", "К" => "K",
            "Л" => "L", "М" => "M", "Н" => "N", "О" => "O", "П" => "P", "Р" => "R",
            "С" => "S", "Т" => "T", "У" => "U", "Ф" => "F", "Х" => "H", "Ц" => "C",
            "Ч" => "CH", "Ш" => "SH", "Щ" => "SH", "Ы" => "I", "Ь" => "", "Ъ" => "",
            "Э" => "E", "Ю" => "YU", "Я" => "YA",
            
		);
    private $delimiter="-";
	
    
    
    public function filter($alias){
    	foreach($this->letters as $letterVal => $letterKey) {
			$alias = str_replace($letterVal, $letterKey, $alias);
		}
		$alias=mb_strtolower($alias,"utf-8");
		//Лишние пробелы
		$alias = preg_replace ( '/\040+/', ' ', $alias );
		//Пробелы нафиг
		$alias = preg_replace ( '/\040/', $this->delimiter, $alias );
		//Символы нехорошие
		//$alias = preg_replace ( '/[\+,*,\/,\&,\',\",\^,\(,\)\?,\\\]/', '', $alias );
		$alias = str_replace(array('\\','[',']','^','!','"','#','%','&',"'",'*',',',':',';','<','>','?','`','{','}','|',),'',$alias);
		$alias = preg_replace ( '/[^a-zA-z0-9-_]/', '', $alias );   	
    	return $alias;
    }
}